package fr.utbm.to52.android_bibtex.controller;

import android.content.Intent;
import android.view.MenuItem;
import fr.utbm.to52.android_bibtex.R;
import fr.utbm.to52.android_bibtex.main.FieldActivity;
import fr.utbm.to52.android_bibtex.main.MainActivity;
import fr.utbm.to52.android_bibtex.model.entry.EntryList;

public class FieldController {

	private final FieldActivity activity;

	public FieldController(FieldActivity activity) {
		this.activity = activity;
	}

	public boolean itemSelectedAction(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menu_saveEntry:
			FieldActivity.entry.setFields(this.activity.getFields());
			MainActivity.entryListChanged = EntryList.getInstance().addEntry(FieldActivity.entry);
			FieldActivity.entry = null;
			this.activity.startActivity(new Intent(this.activity, MainActivity.class));
			return true;
		case R.id.menu_deleteEntry:
			MainActivity.entryListChanged = EntryList.getInstance().removeEntry(FieldActivity.entry.getKey());
			this.activity.startActivity(new Intent(this.activity, MainActivity.class));
			return true;
		default:
			return false;
		}
	}

}
